package com.ying.core.page;

import org.springframework.data.domain.Page;

import java.io.Serializable;
import java.util.List;

/**
 * 分页对象
 * @author 硬
 * @date 2021/12/04 20:13
 */
public class PageData<T> implements Serializable {

    // 目标页
    private int page;

    // 一页多少行
    private int capacity;

    // 总记录数
    private long total;

    // 当前的数据
    private List<T> records;

    public PageData(int page, int capacity,long total, List<T> records) {
        this.page = page;
        this.capacity = capacity;
        this.total = total;
        this.records = records;
    }

    public static <T> PageData<T> from(Page<T> page) {

        PageData<T> pageData = new PageData<T>(page.getNumber()+1, page.getNumberOfElements(),
                page.getTotalElements(), page.getContent());
        return pageData;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getCapacity() {
        return capacity;
    }

    public void setCapacity(int capacity) {
        this.capacity = capacity;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public List<T> getRecords() {
        return records;
    }

    public void setRecords(List<T> records) {
        this.records = records;
    }

}
